<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
// 应用公共文件
//根据当前时间计算下一次打卡剩余时长
function getSignTime($time)
{
    $a = '';
    $nextTime = date("Y-m-d ", strtotime("+1 days"));//下一天日期
    $nowtimestamp = $time;//当前时间戳
    $a = strtotime($nextTime . ' 06:30') - $nowtimestamp;//剩余时间
    return $a;
}

//获取多少天以后的日期
function getEndDate($day){
    $time=date('Y-m-d', strtotime("+".$day." day")).' 07:30';
    return strtotime($time);
}
//根据id获取账号名
function getMobileById($uid){
    $where=[
        'id'=>$uid
    ];
    $res=model('User')->field('mobile')->where($where)->find();

    $str = substr_replace($res['mobile'],'****',3,4);
    return $str;
}
//根据id获取账号名
function getMobile($uid){
    $where=[
        'id'=>$uid
    ];
    $res=model('User')->field('mobile')->where($where)->find();
    return $res['mobile'];
}

//签到状态
function item_status($status){
    $str='';
    switch ($status){
        case 0:
            $str='未打卡';
            break;
        case 1:
            $str='已打卡';
            break;
        default:
            $str='状态错误';
    }
    return $str;
}

//打卡结算状态
function item_count_status($status){
    $str='';
    switch ($status){
        case 0:
            $str='未结算';
            break;
        case 1:
            $str='已结算';
            break;
        default:
            $str='状态错误';
    }
    return $str;
}

//签到时间
function sign_time_str($time){
    if(!$time){
        return '无';
    }
    return date('Y-m-d H:i:s',$time);
}

//签到时间去除年份
function sign_time($time){
    if(!$time){
        return '无';
    }
    return date('H:i:s',$time);
}

//优惠券状态
function discounts_status($status){
    $str='';
    switch ($status){
        case 0:
            $str='领取中';
            break;
        case 1:
            $str='结束领取';
            break;
        default:
            $str='状态错误';
    }
    return $str;
}

//判断是否存在

function isExistCoupon($id){
    $where=[
        'dis_id'=>$id
    ];
    $res=model('UserDiscounts')->where($where)->find();
    if($res){
        return true;
    }else{
        return false;
    }
}



